package modelLayer;
import java.io.Serializable;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;

@SuppressWarnings("serial")
public class Status implements Serializable {
	
	private int statusID;
	private Date startdate;
	private Date finishdate;
	private int dayOrNight; //if 1 day, 2 night
	
	private List<Person> proEmp;
	private List<PartStatus> partStatus;
	
	private int nextPartStatusID = 0;
	
	
	
	public Status()
	{		
		partStatus = new ArrayList<PartStatus>();
	}
	
	public Status(int statusID){
		this.statusID = statusID;
	}
	
	
	public int getStatusID() {
		return statusID;
	}

	public void setStatusID(int statusID) {
		this.statusID = statusID;
	}

	public Date getStartdate() {
		return startdate;
	}
	
	

	public void setStartdate(Date startdate) {
		this.startdate = startdate;
	}

	public Date generateStartDate(){
		//lazy implement
				java.util.Date utilDate = new java.util.Date();
				java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());

				return sqlDate;
	}
	
	public Date getFinishdate() {
		return finishdate;
	}

	public void setFinishdate(Date finishdate) {
		this.finishdate = finishdate;
	}
	
	public Date generateFinishDate(){
		//lazy implement
				java.util.Date utilDate = new java.util.Date();
				java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
			this.finishdate = sqlDate;
				return sqlDate;
	}
	
	public void setDayOrNight(int dayOrNight){
		this.dayOrNight = dayOrNight;
	}
	
	public int getDayOrNight(){
		return dayOrNight;
	}
	
	//Control the partStatus- Lists
	public void addPartStatus(PartStatus partStatus)
	{
		try{
			partStatus.setPartStatusID(nextPartStatusID);
			this.partStatus.add(partStatus);
			nextPartStatusID++;
		}
		catch(Exception e)
		{
			System.out.println("Fail to add PartStatus to list");
			System.out.println("error: " + e.getMessage());
		}
		
	}
	
	//Return object of type PartStatus
	public PartStatus getPartStatus(int partStatusID)
	{
		int i = 0;
		boolean found = false;
		PartStatus p = null;
		
		while(i < partStatus.size() && !found)
		{
			p = partStatus.get(i);
			if(p != null){
			if(p.getPartStatusID() == partStatusID)
			{
//				System.out.println("PartStatus is found");
				found = true;
			}
			}
			i++;
		}
		return p;
	}
	
	
	public PartStatus getPartStatusByID(int partStatusID){
		return this.partStatus.get(partStatusID);
	}
	
	
	//Removes an specific partStatus
	public boolean removePartStatus(int partStatusID)
	{
		PartStatus p = getPartStatus(partStatusID);
		boolean removed = false;
		
		if(p != null)
		{
			this.partStatus.remove(p);
			removed = true;
		}
		
		return removed;
	}
	
	
	//return List<PartStatus>
	public List<PartStatus> getAllPartStatus(){
		return this.partStatus;
	}
	
	
	
	
	//Controls the ProductionEmployee List
	
	public void addProEmployee(Person Employee)
	{
		try{
			this.proEmp.add(Employee);
		}
		catch(Exception e)
		{
			System.out.println("Fail to add ProEmployee to list");
			System.out.println("error: " + e.getMessage());
		}
	}
	
	public Person getEmployee(String fName)
	{
		int i = 0;
		boolean found = false;
		Person proEmp = null;
		
		while(i < this.proEmp.size() && !found)
		{
			proEmp = this.proEmp.get(i);
			if(proEmp.getFname().equalsIgnoreCase(fName))
			{
				found = true;
			}
			i++;
		}
		
		return proEmp;
	}	
	
	
	public boolean removeEmployee(String proEmpName)
	{
		Person proEmp = getEmployee(proEmpName);
		boolean deleted = false;
		if(proEmp != null)
		{
			this.proEmp.remove(proEmp);
			deleted = true;
		}
		return deleted;
	}
	
	public List<Person> getAllPerson(){
		return this.proEmp;
	}
	
	public void setListPerson(List<Person> p){
		this.proEmp = p;
	}	
	
	
	
}
